﻿//<script type="text/javascript">
spsetBase("mrBranch", "BranchID", "mrBranch as T", "*", "#grid1", "mrorg", "机构");
$(function () {
    BindGrid();
    $('#fparentId').combobox({
        editable: false,
        valueField: 'id',
        textField: 'name',
        multiple: false,
        url: sposelUrlBySqlNoState("select[BranchID as id  ,BranchName as name]table[mrBranch]where[type in('本部')]group[]having[]order[BranchID]")

    });
    $("#fparentId").combobox({ disabled: true });
    //$.ajaxSetup({
    //    async: true
    //});
    $("#tablename").val(pTableName);
    $("#tablemidname").val(pTableIdName);


    $('#ftype').combobox({

        onChange: function (newValue, oldValue) {
            if (newValue == "分部")
            {
                $("#fparentId").combobox({ disabled: false });

            }
            else
            {
                $("#fparentId").combobox({ disabled: true });
                $("#fparentId").combobox("select","");
                
            }
        }
    });


});

function BindGrid() {
    $(grid1ID).datagrid({
        pagination: true, //是否显示分页控件
        fitColumns: true, //是否自适应宽度
        fit: true, //是否自适应父容器的大小
        loadMsg: "努力加载中...", //加载数据时，显示的提示信息
        rownumbers: true, //是否显示行号
        singleSelect: true, //是否单选
        remoteSort: false, //是否启用服务器排序
        //sortName: "id", //排序字段
        sortOrder: "ASC", //排序类型
        striped: true, //行显示交替背景
        //toolbar: "#tb", //工具栏
        toolbar: ptoolbar.length == 0 ? null : ptoolbar,
        idField: 'fid',
        pageSize: 10,
        pageList: [10, 20, 30, 40, 50],
        columns: [[
           { field: "BranchID", title: "ID", width: 80, sortable: true },
           { field: "BranchName", title: "名称", width: 80, sortable: true },
           { field: "SimpleCode", title: "代码", width: 80, sortable: true },
           { field: "type", title: "类型", width: 100, sortable: true },
           { field: "City", title: "位置", width: 100, sortable: true }
           //,

           //{
           //    field: "y", title: "操作", width: 50, align: "center", formatter: function (value, row, index) {
           //        //return "<a href='#' style='color: #369591;' onclick='javascript:view(" + index + ")'>查看</a>";
           //        //return "<a href='#' style='color: #369591;' onclick='javascript:Update(" + row.fid + ")'>修改</a>";
           //        return "<a href='#' style='color: #369591;' onclick='javascript:toolUpdate()'>修改</a>";
           //    }
           //}

        ]],
        onLoadSuccess: function (data) {
            switch (data.message) {
                case JsonResult.SessionOut:
                    $.messager.alert('系统出错', ' 登录超时，请重新登录!');
                    break;
                case JsonResult.Error:
                    $.messager.alert('系统出错', data.data);
                    break;
            }
        },
        onBeforeLoad: function (param) {
            if (!$(this).datagrid('options').url) {
                $(this).datagrid('options').url = spselUrl();
            }
            $.extend(param, $("#searchForm").formToJson());
        }
    });
}


function Search() {
    $(grid1ID).datagrid("load");

}

function Reset() {

    $("#finddename").val("");
}


//以下可公用
var SetSelectWithObjIdName = function (sel, objData) {
    $(sel).children().remove();
    $(sel).append("<option value='' selected='selected'></option>");
    for (var i = 0; i < objData.length; i++) {
        if (i == 0) {
            $(sel).append("<option value='" + objData[i].id + "' >" + objData[i].name + "</option>");
        } else {
            $(sel).append("<option value='" + objData[i].id + "'>" + objData[i].name + "</option>");
        }

    }

}
//</script>